%%{init: {'themeVariables': { 'fontSize': '12px'}}}%%
graph TD
    classDef path fill:#eee,stroke:#000,color:#000
    classDef plan fill:#fff,stroke-width:1px,color:#000
    classDef itemplan fill:#fff,stroke-width:2px,color:#000
    classDef unbatchedplan fill:#dff,stroke-width:1px,color:#000
    classDef sideeffectplan fill:#fcc,stroke-width:2px,color:#000
    classDef bucket fill:#f6f6f6,color:#000,stroke-width:2px,text-align:left

    subgraph "Buckets for queries/polymorphic/simple-log-entries"
    Bucket0("Bucket 0 (root)<br /><br />1: <br />ᐳ: 9, 10, 31, 11<br />2: PgSelect[8]<br />3: Connection[12]<br />4: ConnectionItems[14]"):::bucket
    Bucket1("Bucket 1 (nullableBoundary)<br />Deps: 12, 14, 11, 31<br /><br />ROOT Connectionᐸ8ᐳ[12]"):::bucket
    Bucket3("Bucket 3 (listItem)<br />Deps: 11, 31<br /><br />ROOT __Item{3}ᐸ14ᐳ[17]"):::bucket
    Bucket4("Bucket 4 (nullableBoundary)<br />Deps: 18, 11, 31<br /><br />ROOT PgSelectSingle{3}ᐸlog_entriesᐳ[18]<br />1: <br />ᐳ: 19, 20, 21<br />2: PgUnionAll[22]<br />ᐳ: 53, 26, 29, 30, 32, 33, 34"):::bucket
    Bucket5("Bucket 5 (polymorphic)<br />__typename: Access[34]<br />Deps: 34, 33, 11"):::bucket
    Bucket6("Bucket 6 (polymorphicPartition)<br />|Organization<br />Deps: 33, 11<br />ᐳOrganization<br /><br />1: <br />ᐳ: Access[35]<br />2: PgSelect[36]<br />3: PgSelectRows[41]<br />ᐳ: 40, 42, 51"):::bucket
    Bucket7("Bucket 7 (polymorphicPartition)<br />|Person<br />Deps: 33, 11<br />ᐳPerson<br /><br />1: <br />ᐳ: Access[43]<br />2: PgSelect[44]<br />3: PgSelectRows[49]<br />ᐳ: 48, 50, 52"):::bucket
    end
    Bucket0 --> Bucket1
    Bucket1 --> Bucket3
    Bucket3 --> Bucket4
    Bucket4 --> Bucket5
    Bucket5 --> Bucket6 & Bucket7

    %% plan dependencies
    Object11{{"Object[11∈0] ➊<br />ᐸ{pgSettings,withPgClient}ᐳ<br />Dependents: 4"}}:::plan
    Access9{{"Access[9∈0] ➊<br />ᐸ2.pgSettingsᐳ"}}:::plan
    Access10{{"Access[10∈0] ➊<br />ᐸ2.withPgClientᐳ"}}:::plan
    Access9 & Access10 --> Object11
    PgSelect8[["PgSelect[8∈0] ➊<br />ᐸlog_entriesᐳ<br />More deps:<br />- Object[11]"]]:::plan
    __Value2["__Value[2∈0] ➊<br />ᐸcontextᐳ"]:::plan
    __Value2 --> Access9
    __Value2 --> Access10
    Connection12[["Connection[12∈0] ➊<br />ᐸ8ᐳ"]]:::plan
    PgSelect8 --> Connection12
    ConnectionItems14[["ConnectionItems[14∈0] ➊"]]:::plan
    Connection12 --> ConnectionItems14
    __Item17[/"__Item[17∈3]<br />ᐸ14ᐳ"\]:::itemplan
    ConnectionItems14 ==> __Item17
    PgSelectSingle18{{"PgSelectSingle[18∈3]<br />ᐸlog_entriesᐳ"}}:::plan
    __Item17 --> PgSelectSingle18
    PgUnionAll22[["PgUnionAll[22∈4]<br />ᐸPerson,Organizationᐳ<br />More deps:<br />- Object[11]"]]:::plan
    PgClassExpression20{{"PgClassExpression[20∈4]<br />ᐸ__log_entr...person_id”ᐳ"}}:::plan
    PgClassExpression21{{"PgClassExpression[21∈4]<br />ᐸ__log_entr...zation_id”ᐳ"}}:::plan
    PgClassExpression20 & PgClassExpression21 --> PgUnionAll22
    List32{{"List[32∈4]<br />ᐸ29,30,31ᐳ<br />More deps:<br />- Constantᐸ[HIDDEN]ᐳ[31]"}}:::plan
    Access29{{"Access[29∈4]<br />ᐸ26.0ᐳ"}}:::plan
    Access30{{"Access[30∈4]<br />ᐸ26.1ᐳ"}}:::plan
    Access29 & Access30 --> List32
    PgClassExpression19{{"PgClassExpression[19∈4]<br />ᐸ__log_entries__.”id”ᐳ"}}:::plan
    PgSelectSingle18 --> PgClassExpression19
    PgSelectSingle18 --> PgClassExpression20
    PgSelectSingle18 --> PgClassExpression21
    First26{{"First[26∈4]"}}:::plan
    Access53{{"Access[53∈4]<br />ᐸ22.itemsᐳ"}}:::plan
    Access53 --> First26
    First26 --> Access29
    First26 --> Access30
    Lambda33{{"Lambda[33∈4]<br />ᐸtoSpecifierᐳ"}}:::plan
    List32 --> Lambda33
    Access34{{"Access[34∈4]<br />ᐸ33.__typenameᐳ"}}:::plan
    Lambda33 --> Access34
    PgUnionAll22 --> Access53
    PgSelect36[["PgSelect[36∈6]^<br />ᐸorganizationsᐳ<br />More deps:<br />- Object[11]"]]:::plan
    Access35{{"Access[35∈6]<br />ᐸ33.organization_idᐳ<br />ᐳOrganization"}}:::plan
    Access35 --> PgSelect36
    Lambda33 --> Access35
    First40{{"First[40∈6]^"}}:::plan
    PgSelectRows41[["PgSelectRows[41∈6]^"]]:::plan
    PgSelectRows41 --> First40
    PgSelect36 --> PgSelectRows41
    PgSelectSingle42{{"PgSelectSingle[42∈6]^<br />ᐸorganizationsᐳ"}}:::plan
    First40 --> PgSelectSingle42
    PgClassExpression51{{"PgClassExpression[51∈6]^<br />ᐸ__organiza...s__.”name”ᐳ"}}:::plan
    PgSelectSingle42 --> PgClassExpression51
    PgSelect44[["PgSelect[44∈7]^<br />ᐸpeopleᐳ<br />More deps:<br />- Object[11]"]]:::plan
    Access43{{"Access[43∈7]<br />ᐸ33.person_idᐳ<br />ᐳPerson"}}:::plan
    Access43 --> PgSelect44
    Lambda33 --> Access43
    First48{{"First[48∈7]^"}}:::plan
    PgSelectRows49[["PgSelectRows[49∈7]^"]]:::plan
    PgSelectRows49 --> First48
    PgSelect44 --> PgSelectRows49
    PgSelectSingle50{{"PgSelectSingle[50∈7]^<br />ᐸpeopleᐳ"}}:::plan
    First48 --> PgSelectSingle50
    PgClassExpression52{{"PgClassExpression[52∈7]^<br />ᐸ__people__.”username”ᐳ"}}:::plan
    PgSelectSingle50 --> PgClassExpression52

    %% define steps
    classDef bucket0 stroke:#696969
    class Bucket0,__Value2,PgSelect8,Access9,Access10,Object11,Connection12,ConnectionItems14 bucket0
    classDef bucket1 stroke:#00bfff
    class Bucket1 bucket1
    classDef bucket3 stroke:#ffa500
    class Bucket3,__Item17,PgSelectSingle18 bucket3
    classDef bucket4 stroke:#0000ff
    class Bucket4,PgClassExpression19,PgClassExpression20,PgClassExpression21,PgUnionAll22,First26,Access29,Access30,List32,Lambda33,Access34,Access53 bucket4
    classDef bucket5 stroke:#7fff00
    class Bucket5 bucket5
    classDef bucket6 stroke:#ff1493
    class Bucket6,Access35,PgSelect36,First40,PgSelectRows41,PgSelectSingle42,PgClassExpression51 bucket6
    classDef bucket7 stroke:#808000
    class Bucket7,Access43,PgSelect44,First48,PgSelectRows49,PgSelectSingle50,PgClassExpression52 bucket7

